package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.Answer;
import cn.wolfcode.trip.base.service.IAnswerService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("answers")
public class AnswerController {
    @Autowired
    private IAnswerService answerService;

    @PostMapping
    public JsonResult save(Answer answer, Long questionId) {
        JsonResult result = new JsonResult();
        answerService.savaOrUpdate(answer, questionId);
        result.setErrorMsg("回答成功,正在跳转..");
        return result;
    }

    @GetMapping("{answerId}")
    public Answer get(@PathVariable Long answerId) {
        return answerService.get(answerId);
    }

    @PostMapping("comments")
    public JsonResult saveComment(Answer answer) {
        JsonResult result = new JsonResult();


        result.setErrorMsg("评论成功,正在跳转..");
        return result;
    }
}
